<?php
include ('check_login.include.php');
include ('../classes/autoloading_pages.include.php');

define(ACTION, 'action');
define(ACTION_ARCHIVE, 'archive');
define(ACTION_ARTICLE, 'read');
define(ARTICLE_ID, 'id');
define(ARTICLE_SEO, 'seo');
define(FILTER, 'filter');
define(FILTER_FDG, 'fdg');
define(FILTER_FDR, 'fdr');

$hm = new HTMLElementsManager();
$navigation = $hm->get_HTML_element_by_name('navigation');
$header = $hm->get_HTML_element_by_name('header');
$footer = $hm->get_HTML_element_by_name('footer');

if (isset($_GET[ACTION])) {
    $am = new ArticlesManager();
    if ($_GET[ACTION] == ACTION_ARCHIVE) {
        $articles = null;
        if (isset($_GET[FILTER])) {
            if ($_GET[FILTER] == FILTER_FDG) { // Filtro FdG
                $articles = $am->get_publicated_fdg_articles($logged);
            } else if ($_GET[FILTER] == FILTER_FDR) { // Filtro FdR
                $articles = $am->get_publicated_fdr_articles($logged);
            }
        } else { // Nessun filtro
            $articles = $am->get_publicated_articles($logged);
        }
    } else if ($_GET[ACTION] == ACTION_ARTICLE) {
        $article = null;
        if (isset($_GET[ARTICLE_ID]) && isset($_GET[ARTICLE_SEO])) {
            $article = $am->get_article_by_id($_GET[ARTICLE_ID], $_GET[ARTICLE_SEO], $logged);
        }
    }
}

include ('article.view.php');
?>
